<template>
  <div class="app-main">
    <div class="main-header">
      <el-page-header @back="reset('ruleForm')" content="编辑项目" />
      <div class="header-right">
        <el-button size="mini" @click="reset('ruleForm')">取 消</el-button>
        <el-button size="mini" type="primary" :loading="loading" @click="update('ruleForm')" >确 定</el-button>
      </div>
    </div>
    <div class="main-contain">
    </div>
  </div>
</template>

<script>
export default {
  name: 'editProject',
  data () {
    return {
      loading: false,
      list: {
        data: [],
        loading: false,
        page: 1,
        total: 0,
        size: 1000,
        filters: {
          search: '',
          prop: '',
          order: ''
        }
      },
      ruleForm: {
        name: '',
        desc: '',
        type: 1,
        path: '',
        url: '',
        status: 1
      },
      rules: {
        name: [
          { required: true, message: '请输入项目名称', trigger: 'blur' }
        ]
      }
    }
  },
  created() {
    // this.getList()
  },
  methods: {
    reset(formName) {
      this.$refs[formName].resetFields()
      this.$router.go(-1)
    },
    getList () { // 获取项目文档列表
      this.list.loading = true
      this.$API({
        name: 'GetProjectDocumentList',
        params: {
          pid: this.$route.params.id,
          page: this.list.page,
          size: this.list.size,
          search: this.list.filters.search,
          order: this.list.filters.prop,
          sort: this.list.filters.order
        },
        requireAuth: true
      }).then (res => {
        if (res.data.code === 200) {
          this.list.data = res.data.data.data
        } else {
          this.$message.error(res.data.msg)
        }
      }).catch(error => {
        this.$message.error(error)
      }).finally(() => {
        this.list.loading = false
      })
    },
    update(formName) { // 修改
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.loading = true
          const params = {
            id: this.$route.params.id,
            name: this.ruleForm.name,
            type: this.ruleForm.type,
            path: this.ruleForm.path,
            url: this.ruleForm.url,
            status: this.ruleForm.status,
            desc: this.ruleForm.desc,
            uid: this.$Cookies.get('uid')
          }
          this.$API({
            name: 'UpdateProject',
            data: params,
            requireAuth: true
          }).then(res => {
            if (res.data.code === 200) {
              this.$router.go(-1)
            } else {
              this.$message.error(res.data.msg)
            }
          }).catch(error => {
            this.$message.error(error)
          }).finally(() => {
            this.loading = false
          })
        }
      })
    },
    detali (id) { // 根据id获取详情
      this.$API({
        name: 'DetailProjectDocument',
        paths: [id],
        requireAuth: true
      }).then (res => {
        if (res.data.code === 200) {
          this.ruleForm = res.data.data
        } else {
          this.$message.error(res.data.msg)
        }
      }).catch(error => {
        this.$message.error(error)
      })
    },
  }
}
</script>

<style lang="scss" scoped>
::v-deep .el-form-item {
  margin-bottom: 15px !important;
}
.app-main {
  .main-header {
    height: 31px;
    width: 100%;
    border-bottom: 1px solid #DCDFE6;
    flex-shrink: 0;
    display: flex;
    justify-content: space-between;
  }
  .main-contain {
    padding-top: 10px;
    overflow-y: auto;
    width: 100%;
    flex: 1 1 auto;
    .contain-item {
      .el-form-item {
        padding: 0 5px;
        flex: 1;
      }
      .el-rate {
        border-radius: 4px;
        border: 1px solid #DCDFE6;
        padding: 0 15px
      }
      .form-item-tag {
        border-radius: 4px;
        border: 1px solid #DCDFE6;
        padding: 0 15px;
      }
    }
    .el-rate {
      height: 40px !important;
      line-height: 2.5 !important;
    }
    .contain-editor {
      width: 100%;
      height: 150px;
      display: flex;
      flex-direction: column;
      .editor-nav {
        display: flex;
        align-items: center;
        justify-content: space-between;
        margin-bottom: 10px;
        padding: 0 5px;
        font-size: 14px;
        color: #606266;
        line-height: 40px;
      }
      .editor {
        flex: 1 1 auto;
      }
    }
  }
}
</style>